Fold comparisons into single-value ranges in GetRangeFromAssertions#123624
Merged
EgorBo merged 11 commits intodotnet:mainfrom Jan 29, 2026
Merged
Fold comparisons into single-value ranges in GetRangeFromAssertions#123624EgorBo merged 11 commits intodotnet:mainfrom
EgorBo merged 11 commits intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib |
…1 into fold-cmp-from-assertions
This was referenced Jan 27, 2026
Open
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines range analysis and assertion propagation so that relational comparisons can often be recognized as always-true or always-false, allowing more branches to be folded.
Changes:
- Extend
Range/RangeOpsto represent and compute the result of relational operators as[0..0],[1..1], or[0..1]ranges, including improved handling ofEQ/NEwhen operand ranges are disjoint or equal singletons. - Enhance
RangeCheck::GetRangeFromAssertionsto useGetRangeFromType, refine cast ranges using the source expression’s range, and to interpret comparison VNFs viaRangeOps::EvalRelop, with an early-exit when a single constant value is determined. - Update
optAssertionPropGlobal_RelOpto use range information for the entire relop VN (instead of separate operand ranges) and fold comparisons directly when their range is a single constant 0 or 1.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/coreclr/jit/rangecheck.h | Adds Range::IsSingleValueConstant and changes RangeOps::EvalRelop to return a Range capturing 0/1 semantics instead of a tri-state enum; RangeCheck::GetRangeFromType is made static. |
| src/coreclr/jit/rangecheck.cpp | Refactors GetRangeFromAssertions to use GetRangeFromType for casts, use EvalRelop for VN comparison functions, early-return for single-value ranges, and slightly restructures the reaching-assertions visitor. |
| src/coreclr/jit/assertionprop.cpp | Switches global relop assertion propagation to query the range of the relop’s value number and fold to true/false when the computed range is a single constant 0 or 1. |
Member
Author
|
PTAL @jakobbotsch @dotnet/jit-contrib the last piece for now. Diffs CI was green once, now it's mostly deadlettering. |
This was referenced Jan 28, 2026
Contributor
|
It seems that this also mixed some regressions for example the bound check in |
jakobbotsch
approved these changes
Jan 29, 2026
Member
Author
|
/ba-g deadletter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR does:
[0..1], now it tries to fold it to[0..0](always false) or[1..1](always true)GT_EQ/GT_NEoperators when ranges are single-value constants.Diffs